<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="njtc" uri="http://www.njtcedu.cn/app/core" %>

<div class="content" id="content" data-nav="nav_user">
    <h1>用户列表<span></h1>
    
    <div class="manage">
        <form action="${pageContext.request.contextPath}/intranet/userlist/10" method="post" id="userSearch" class="filter">
            <label for="account">账号：</label>
            <input type="text" name="account" id="userAccount"/>
            
            <label for="nickName">昵称</label>
			<input type="text" name="nickName" id="userNickname"/>
			
			<label for="signupDateFrom">注册日期 From:</label>
			<input type="text" name="signupDateFrom" id="signupDateFrom" class="dateinput"/>
			<label for="signupDateTO">To:</label>
			<input type="text" name="signupDateTO" id="signupDateTO" class="dateinput"/>
            <input type="submit" value="搜索"/>
        </form>
        
        <c:if test="${not empty pageModel}">
	        <div class="itemList userList">
	            <table>
	                <thead>
		                <tr>
		                   <th>账号</th>	
		                   <th>账户类型</th>
		                   <th>昵称</th>
				           <th>Email</th>
				           <th>注册日期</th>
				           <th></th>
		                </tr>
	                </thead>  
	                 
	                <tbody id="userList" data-pagenav="userPageNav">
					<c:choose>
						<c:when test="${not empty pageModel.records}">
							<c:forEach var="user" items="${pageModel.records}">
								<tr>
									<td>${ user.userAccount.account }</td>
									<input type="hidden" name="userId" value="${ user.userAccount.id }">
									<td>${ user.userAccount.userType }</td>
									<td>${ user.nickName }</td>
									<td>${ user.email }</td>
									<td><fmt:formatDate value="${ user.signupDate }"  type="both" pattern="yyyy-MM-dd HH:mm"/></td>
									<td><a href="${pageContext.request.contextPath}/user/delete/${ user.userAccount.id }" class="deleteUser">删除</a></td>
								</tr>
							</c:forEach>
						</c:when>
						<c:otherwise>
								<tr>
									<td colspan="25">No Recodes.</td>
								</tr>
						</c:otherwise>
					</c:choose>
	                </tbody>
	            </table>
	            <njtc:pageQuery url="${pageContext.request.contextPath}/intranet/userlist" pageNo="${pageModel.pageNo}"  pageSize="${pageModel.pageSize}"  totalRecords="${pageModel.totalRecords}"/>
	        </div>
        </c:if>
    </div>
</div>
<script>
    $('.deleteUser').ajaxBind(
	    {
	       type: 'DELETE'
	    },
		{
	        onSuccess: function(data, self){
	        	if(data){
	        		self.parents('tr').remove();
	        	}
	        }
	    }
    );
    
    $('.pageNav').each(function(){
    	 var select = $(this);
		 var remoteUrl = select.data('remote');
		 if(!remoteUrl) return;
		 $(this).find("select").change(function(){
			location.href= remoteUrl+ "/1/" + $(this).val();
		 });
		 
    });
</script>
